package service.impl;

import dao.UserDao;
import dao.impl.UserDaoImpl;
import entity.Users;
import service.UserService;
import util.StrUtils;

import java.util.Date;

/**
 * User: key
 * ClassName:UserServiceImpl
 * Date: 2023/5/6
 * Time: 15:06
 * description:
 */
public class UserServiceImpl implements UserService {
    private UserDao ud = new UserDaoImpl();
    @Override
    public Users doLogin(String userCode, String password) {
        try {
            if(StrUtils.isNotEmpty(userCode)){
                Users user = ud.getUser(userCode);
                if(StrUtils.isNotEmpty(password)&&user.getPassword().equals(password)){
                    return user;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean reg(Users u) {
        try {
            if (u != null) {
                u.setRegisterTime(new Date());
                if(ud.addUser(u)>0){
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
